package com.dao;

import com.model.Usingrecord;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;
import java.util.Map;

/**
 * @Author: wonzeng
 * @CreateTime: 2020-09-11
 */
public interface UsingDeviceDao {

    @Update("update tb_usingrecord set usi_returnstatus='待处理' where usi_id=#{arg0}")
    public int giveBack(String uri_id);

    /**
     *  用户、管理员查看设备使用申请详情
     * @param ob
     * @return
     */
    @Select("SELECT u.*,a.user_name,b.equ_name from tb_usingrecord u,tb_user a,tb_equipment b where a.user_id = u.user_id AND b.equ_id = u.equ_id")
    public List<Usingrecord> usiRecordInfo(Map<String, Object> ob);
    /**
     *  用户、管理员查看设备使用申请详情
     * @param ob
     * @return
     */
    @Select("SELECT u.*,a.user_name,b.equ_name from tb_usingrecord u,tb_user a,tb_equipment b where a.user_id = u.user_id AND b.equ_id = u.equ_id and b.equ_id=#{arg0}")
    public List<Usingrecord> usiRecordInfoByEquId(Integer equId);


    /**
     * 删除使用记录
     * deltype int,usiid int,out result int
     * @param ob
     * @return
     */
    @Select("call pro_delusingrecord(#{user_type},#{usi_id},#{result,mode=OUT,jdbcType=INTEGER})")
    @Options(statementType=StatementType.CALLABLE)
    public void delusingrecord(Map<String, Object> ob);

    /**
     * 管理员处理使用申请
     * 参数：记录编号、设备编号、借用数量、申请状态、申请处理结果、归还状态、归还处理结果
     *
     * @param param
     * @return
     */
    @Update("update tb_usingrecord set usi_applystatus=#{usi_applystatus},adm_feedbackapply=#{adm_feedbackapply} ,usi_returnstatus =#{usi_returnstatus} where usi_id=#{usi_id}")
    public int admdealusi(Map<String, Object> param);

    /**
     * 申请设备使用
     * @param mp
     */
//	@Results({@Result(column="result", property="result", jdbcType= JdbcType.INTEGER)})
//    @Select("call pro_borrowequ(#{user_id},#{equ_id},#{usi_reason},#{usi_size},#{usi_date},#{usi_day},#{result,mode=OUT,jdbcType=INTEGER})")
//    @Options(statementType=StatementType.CALLABLE)
    @Insert("insert into tb_usingrecord(user_id,equ_id,adm_id,usi_reason,usi_number,usi_date,usi_returndate) values(#{user_id},#{equ_id},'G0001',#{usi_reason},#{usi_number},#{usi_date},#{usi_returndate})")
    public void borrowEquipment(Map<String, Object> mp);

    @Delete("delete from tb_usingrecord where usi_id=#{usiId}")
    void deleteById(Integer usiId);

}
